<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Addeventnews action form.
 * 添加活动(新鲜事)的表格.
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.1
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Requirements.
require_once INSTALLDIR . '/lib/slh_form.php';
require_once INSTALLDIR . '/lib/slh_editor.php';

require_once INSTALLDIR . '/lib/slh_imagefile.php';

require_once INSTALLDIR . '/classes/Poster.php';


class AddeventnewsForm extends Form
{
	/**
	 * The editor widget.
	 */
	var $editor;
	
	function prepareData()
	{
		$this->editor = new Editor('rendered', $this->out);
		
		$this->out->hidden('upload_action', slh_action2url('uploadposterjson'));
		$this->out->hidden('crop_action', slh_action2url('cropposterjson'));
		
		$this->out->hidden('originalname', '');
		
		$this->out->hidden('poster_id', '0');
		foreach (array('poster_crop_x', 'poster_crop_y', 'poster_crop_w', 'poster_crop_h') as $crop_info) {
			$this->out->hidden($crop_info, '');
		}
		
		$this->out->hidden('association_ids', '');
	}
	
	/**
	 * ID of the from
	 */
	function id()
	{
		return 'id_form_addeventnews';
	}
	
	/**
	 * Class of the form.
	 */
	/*
	function formClass()
	{
		// return 'class_settingsform';
	}
	*/
	
	/**
	 * Action of the form
	 * 
	 * Return the string URL of the action.
	 */
	function action()
	{
		return slh_action2url('addeventnews');
	}
	
	/**
	 * The form's legend.
	 */
	function formLegend()
	{
		$this->out->element('legend', null, 'event news');		
	}
	
	/**
	 * Data elements.
	 */
	function formData()
	{
		$this->out->elementStart('dl', array('class' => 'cls_dl_form'));
		
		$this->out->element('dt', array('id' => 'id_anchor_poster'), '活动的海报!');
		$this->out->elementStart('dd');
			$this->out->elementStart('ul');
			$this->out->elementStart('li');
			$this->out->elementStart('div', array('class' => 'cls_div_thumbnailwrapper'));
			$this->out->element('img', array('id' => 'id_img_preview',
											 'style' => 'display:none;'));
			$this->out->elementEnd('div');
			$this->out->elementEnd('ul');
			$this->out->elementEnd('li');
		$this->out->elementEnd('dd');
		
		$this->out->element('dt');
		$this->out->elementStart('dd', array('id' => 'id_dd_upload'));
		$this->out->elementStart('ul');
			$this->out->hidden('MAX_FILE_SIZE',
							   ImageFile::maxPictureSizeInt());
			
			$this->out->elementStart('li');
			$this->out->element('label', array('for' => 'posterfile'), '上传海报!');
			$this->out->inputtips('海报的规格为95*115(暂不支持190*115), 图片大小限制为:' . ImageFile::maxPosterSize());
			$this->out->element('input', array('id' => 'posterfile',
											   'name' => 'posterfile',
											   'type' => 'file',
											   'onChange' => 'ajaxFileUpload();'));
			$this->out->elementEnd('li');
			
			$this->out->elementStart('li', 'cls_li_radio');
				$this->out->element('input', array('id' => 'poster_single_size',
												   'type' => 'radio',
												   'name' => 'poster_size',
												   'value' => POSTER_SINGLE_SIZE,
												   'checked' => 'checked'));
				$this->out->element('label', array('for' => 'poster_single_size'), '95*105');
				
				// Ingoring the 190*115 currently
				$this->out->element('input', array('id' => 'poster_double_size',
												   'type' => 'radio',
												   'name' => 'poster_size',
												   'value' => POSTER_DOUBLE_SIZE,
												   'disabled' => 'disabled'));
				$this->out->element('label', array('for' => 'poster_double_size'), '190*105');
			$this->out->elementEnd('li');
		$this->out->elementEnd('ul');
		$this->out->elementEnd('dd');
		
		$this->out->element('dt', array('id' => 'id_dt_crop',
												'style' => 'display:none'), '裁剪海报');
		$this->out->elementStart('dd', array('id' => 'id_dd_crop',
											 'style' => 'display:none'));
		$this->out->elementStart('ul');
			$this->out->elementStart('li');
			$this->out->element('h5', null, '裁剪之前:');
			$this->out->elementStart('div', array('id'	=> 'poster_original'));
			$this->out->element('img');
			$this->out->elementEnd('div');
			$this->out->elementEnd('li');
			
			$this->out->elementStart('li');
			$this->out->element('h5', null, '裁剪之后:(记得点裁剪!)');
			$this->out->elementStart('div', array('id'	=> 'poster_preview',
												  'height' => '230px',
												  'width' => '190px',
												  'overflow' => 'hidden'));
			$this->out->element('img');
			$this->out->elementEnd('div');
			$this->out->elementEnd('li');

			$this->out->elementStart('li');
			$this->out->element('input', array('id' => 'submit_crop',
											   'name' => 'submit',
											   'type' => 'button',
											   'value' => '裁剪!',
											   'onClick' => 'ajaxPosterCrop();'));
			$this->out->elementEnd('li');
		$this->out->elementEnd('ul');
		$this->out->elementEnd('dd');
		
		$this->out->element('dt', 'csshide', '上传信息');
		$this->out->elementStart('dd', array('class' => 'dd_cls_tips'));
		$this->out->elementStart('ul');
			$this->out->elementStart('li');
			$this->out->elementStart('div', array('class' => 'cls_div_thumbnailwrapper'));
			$this->out->element('img', array('id' => 'id_img_loading',
											 'src' => slh_full_path('theme/base/common/loading.gif'),					
											 'style' => 'display:none;'));
			$this->out->elementEnd('div');
			$this->out->elementEnd('li');
			
			$this->out->element('div', array('id' => 'id_div_tips'));
		$this->out->elementEnd('ul');
		$this->out->elementEnd('dd');
		
		$this->out->element('dt', null, '活动信息');
		$this->out->elementStart('dd');
		$this->out->elementStart('ul');
			$this->out->elementStart('li');
			$this->out->input('title',
							  '活动名称',
							  $this->getField('title'),
							  '就是这个活动如雷贯耳的名字呃.');
			$this->out->elementEnd('li');
			
			$this->out->elementStart('li');
			$this->out->textarea('message',
								 '活动简介',
								 4,
								 60,
								 $this->getField('message'),
								 '简单描述下这个活动(200个字以内)啊,亲.');
			$this->out->elementEnd('li');
			
			$this->out->elementStart('li');
			$this->out->input('host',
							  '活动组织方',
							  $this->getField('host'),
							  '活动的主要 主办/承办 社团/组织');
			$this->out->elementEnd('li');
			
			$this->out->elementStart('li');
			$this->out->input('address',
							  '活动地点',
							  $this->getField('address'),
							  '总要告诉别人在哪里搞活动吧.');
			$this->out->elementEnd('li');
			
			$this->out->elementStart('li');
			$this->out->datetimepicker('started',
									   'started_date',
									   'started_hour',
									   'started_minute',
									   '开始时间',
									   '活动的开始时间.');
			$this->out->elementEnd('li');
			
			$this->out->elementStart('li');
			$this->out->datetimepicker('ended',
									   'ended_date',
									   'ended_hour',
									   'ended_minute',
									   '结束时间',
									   '活动的结束时间.');
			$this->out->elementEnd('li');
			
			$this->out->element('dt', null, '活动的详细介绍');
			$this->out->inputtips('有多详细写多详细哈,亲.');
			$this->out->elementStart('li', 'cls_li_eaditor');
			$this->editor->show();
			$this->out->elementEnd('li');
		$this->out->elementEnd('ul');
		$this->out->elementEnd('dd');
			
		$this->out->elementEnd('dl');
	}
	
	/**
	 * Action elements.
	 */
	function formActions()
	{
		$this->out->elementStart('div', 'formaction');
		$this->out->submit('submit',
						   '发布',
						   'submit',
						   'add',
						   '发布一个活动新鲜事.');
		$this->out->elementEnd('div');
	}
}